package com.mcc.myapplication.frame;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.mcc.myapplication.R;

/**
 * A fragment representing a list of Items.
 */
public class LeftFragment extends Fragment {

    private static String ARG_PARAM = "param_key";
    private String mParam;
    private Activity mActivity;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mActivity = (Activity) context;
        mParam = getArguments().getString(ARG_PARAM);  //获取参数

//        if (context instanceof Activity) {
//            mActivity = (Activity) context;
//        } else {
//            throw new RuntimeException(context.toString()
//                    + " must implement OnFragmentInteractionListener");
//        }

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.left_fragment, container, false);
        TextView view = root.findViewById(R.id.left_text_1);
        view.setText(mParam);
        return root;
    }

    public static LeftFragment newInstance(String str) {
        LeftFragment fragment = new LeftFragment();
        Bundle bundle = new Bundle();
        bundle.putString(ARG_PARAM, str);
        bundle.putString("key2", "Hello");
        fragment.setArguments(bundle);   //设置参数
        return fragment;
    }

}